<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>async await</title>
</head>

<body>
  <script>
    // 创建一个Promise对象
    const p = new Promise((resolve, reject) => {
      // resolve("用户数据");
      reject("没拿到 对不起...");
    })

    // await要放在 async函数中
    async function main() {
      // 失败需要通过try...catch捕获
      try {
        // 只返回Promise成功的值
        const res = await p;
        console.log(res);
      } catch (e) {
        console.log("Promise失败了", e);
      }
    }

    main();
  </script>
</body>

</html>